<?php
/*
 * @Create By: Vscode
 * @Author: falcon
 * @Date: 2020-08-09 22:12:38
 * 查库基础model
 */
namespace application\model;
use application\depend\Dbiov;
use application\depend\Applog;
class PdoModel {
    // select
    public static function selectData($sql,$sqlData,$description){
        try{
            $pdo = Dbiov::getInstance();
            $result = $pdo->selectResult($sql,$sqlData);
            if(false === $result){
                $e = ['title'=>$description,'sql'=>$sql,'error' => $pdo->presqlErrInfo];
                Applog::errorLog($e,__FILE__,__LINE__);
                $pdo->closeDb();
                return false;
            }
            return $result;
        }catch(\Exception $e){
            $e = ['title'=>$description . ' e-catch','sql'=>$sql,'error' => $pdo->presqlErrInfo];
            Applog::errorLog($e,__FILE__,__LINE__);
            $pdo->closeDb();
            return false;
        }
        
    } // func

    // insert ; 最好sqlData里面的数组key 跟 数据库的字段是一样的。
    public static function insertData($table,$sqlData,$description){
        $pdo = Dbiov::getInstance();
        try{
            $result = $pdo->insert($table,$sqlData);
            if(false === $result){
                $e = ['title'=>$description,'error' => $pdo->presqlErrInfo];
                Applog::errorLog($e,__FILE__,__LINE__);
                $pdo->closeDb();
                return false;
            }
            return $result;
        }catch(\Exception $e){
            $e = ['title'=>$description . ' e-catch','error' => $pdo->presqlErrInfo];
            Applog::errorLog($e,__FILE__,__LINE__);
            $pdo->closeDb();
            return false;
        }
    }// func
}// class